package com.yanqu.road.thread;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolHelper {

	private static ThreadPoolExecutor threadPoolExecutor;

	public static void exec(Runnable task) {
		threadPoolExecutor.execute(task);
	}

	public static boolean init() {
		int cpSize = Runtime.getRuntime().availableProcessors() * 2;
		long keepAlive = 5;
		threadPoolExecutor = new ThreadPoolExecutor(cpSize, cpSize * 2, keepAlive, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>(),  new ThreadPoolExecutor.DiscardPolicy());
		return true;
	}
}
